const path = require("path");
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";

// 配置完成之后使用ref reactive watch 等 无须import 导入 可以直接使用
import AutoImport from "unplugin-auto-import/vite";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    AutoImport({
      imports: ["vue"],
      dts: "src/auto-import.d.ts",
    }),
  ],

  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
      // "/@/": path.resolve(__dirname, "./src"),
    },
  },
  server: {
    // hostname: '0.0.0.0',
    host: "localhost",
    port: 3001,
    // 是否自动在浏览器打开
    open: true,
    // 是否开启 https
    // https: false,
    // 服务端渲染
    // ssr: false,
    proxy: {
      "/api": {
        target: "http://localhost:3333/",
        changeOrigin: true,
        ws: true,
        rewrite: (pathStr) => pathStr.replace("/api", ""),
      },
    },
  },
  // 打包生成dist文件夹，html引用的路径不对
  base: "./",
});
